package com.archie.zhufengfm.tasks;

import com.archie.zhufengfm.Constants;
import com.archie.zhufengfm.client.ClientAPI;
import com.archie.zhufengfm.utils.EntityParseUtil;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Archie on 2015/10/23.
 */
public class AlbumsTask extends BaseTask {

    private long albumId, trackId;
    private int pager;

    public AlbumsTask(TaskCallback callback, long albumId, long trackId, int pager) {
        super(callback);

        this.albumId = albumId;
        this.trackId = trackId;
        this.pager = pager;
    }


    @Override
    protected TaskResult doInBackground(String... params) {
        TaskResult ret = new TaskResult();

        ret.action = Constants.TASK_ACTION_OTHERS;

        JSONObject jsonObject = ClientAPI.getAlbums(albumId, trackId, pager);

        if (jsonObject != null) {
            try {

                ret.resultCode = jsonObject.getInt("ret");
                ret.data = EntityParseUtil.parseAlbumDetails(jsonObject);

            } catch (JSONException e) {
                e.printStackTrace();
            }

        }

        return ret;
    }
}
